/**
 *
 * Created by Song,YeWen, 10/9/2011 11:47:42 AM
 *
 */

function  validateVideoUrl(ori_url) 
{
    //We use a fake constant duration for joy.cn, because it is short News/Entertainment, not long duration video
    //TODO: FIXME
    var fcduration = '100'; 
	var html = download_page(ori_url);
	var matches = html.match(/contentId:"(\d+)"/);
	if (!matches) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	var dst_url = 'http://msx.app.joy.cn/service.php?action=msxv6&videoid=' + matches[1];
	var xml_str = download_page(dst_url);
	var flv_path = parse_xml(xml_str, 'entry', 'item', 'Url');
	var host_path = parse_xml(xml_str, 'entry', 'item', 'HostPath');
	var flv_str = host_path + flv_path;
	
	//matches = html.match(/<title>(.*?)<\/title>/);
	matches = html.match(/<title>([\s\S]*?)<\/title>/);
    if(matches){
 	   return 'success_title:' + encodeURIComponent(matches[1])
 	          + '\n video_urls:' + encodeURIComponent(flv_str)
 	          + '\n seconds:' + Math.round(parseInt(fcduration));
    }
    return 'error:empty_path';
}

/* http://msx.app.joy.cn/service.php?action=msxv6&videoid=3217585 */
/* http://news.joy.cn/album/439676/1/1/3217585.htm */
function js_get_media_url(ori_url) 
{
	var html = download_page(ori_url);
	var matches = html.match(/contentId:"(\d+)"/);
	if (!matches) {
		// Not Found
		return '';
	}
    
	var dst_url = 'http://msx.app.joy.cn/service.php?action=msxv6&videoid=' + matches[1];
	var xml_str = download_page(dst_url);
	var flv_path = parse_xml(xml_str, 'entry', 'item', 'Url');
	var host_path = parse_xml(xml_str, 'entry', 'item', 'HostPath');
	var flv_str = host_path + flv_path;
	
	return flv_str;
}
